﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Gedea.Core.Manager.DataAccess
{
    public class DataLookFor : DataCommon
    {
        public List<T> List<T>()
            where T : new()
        {
            string query = string.Format("SELECT * FROM {0}",
                GetTableName<T>());

            return ListEntity<T>(query);
        }

        public List<T> List<T>(string whereClause)
            where T : new()
        {
            string query = string.Format("SELECT * FROM {0} {1}",
                GetTableName<T>(), 
                whereClause);

            return ListEntity<T>(query);
        }

        public T Get<T>()
            where T : new()
        {
            string query = string.Format("SELECT TOP 1 * FROM {0}",
                GetTableName<T>());

            return GetEntity<T>(query);
        }

        public T Get<T>(string whereClause)
            where T : new()
        {

            string query = string.Format("SELECT TOP 1 * FROM {0} {1}",
                GetTableName<T>(), 
                whereClause);

            return GetEntity<T>(query);
        }
    }
}
